package com.hibernate.rcache.region;

import com.rcache.core.cache.Rcache;
import com.rcache.core.manager.CacheManager;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.internal.Timestamper;
import org.hibernate.cache.spi.TimestampsRegion;

import java.util.Map;
import java.util.Properties;

public class RcacheTimestampsRegion implements TimestampsRegion {

   private CacheManager cacheManager;
    private Rcache cache;
    private Properties properties;
    public RcacheTimestampsRegion(CacheManager cacheManager, Rcache cache, Properties properties) {
        this.cacheManager=cacheManager;
        this.cache=cache;
        this.properties=properties;
    }

    public Object get(Object key) throws CacheException {
        return cache.get(key).getObjectValue();
    }

    public void put(Object key, Object value) throws CacheException {
       cache.put(key,value);
    }

    public void evict(Object key) throws CacheException {
        cache.remove(key);
    }

    public void evictAll() throws CacheException {
        cache.clear();
    }

    public String getName() {
        return cache.getCacheName();
    }

    public void destroy() throws CacheException {
        cache=null;
    }

    public boolean contains(Object key) {
        return cache.containsKey(key);
    }

    public long getSizeInMemory() {
        return cacheManager.getSizeInMemory();
    }

    public long getElementCountInMemory() {
        return cacheManager.getElementCountInMemory();
    }

    public long getElementCountOnDisk() {
        return 0;
    }

    public Map toMap() {

        return cache.toMap();
    }

    public long nextTimestamp() {
        return Timestamper.next();
    }

    public int getTimeout() {
        return cacheManager.getTimeout();
    }
}
